//
//  VC3Evaluate.swift
//  ChapterAll
//
//  Created by Kevin on 2020/4/23.
//  Copyright © 2020 Kevin. All rights reserved.
//

import UIKit
import StoreKit
import MessageUI

class VC3Evaluate: UIViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // Do any additional setup after loading the view.
        
        let btn1 =  getBtn(str: "评价", btn: UIButton())
        btn1.addTarget(self, action: #selector(clickBtn1), for: .touchUpInside)
        view.addSubview(btn1)
        
        let btn2 = getBtn(str: "打电话", btn: btn1)
        btn2.addTarget(self, action: #selector(clickBtn2), for: .touchUpInside)
        view.addSubview(btn2)
        
        let btn3 = getBtn(str: "发短信", btn: btn2)
        btn3.addTarget(self, action: #selector(clickBtn3), for: .touchUpInside)
        view.addSubview(btn3)
    }
    
    @objc func clickBtn1() -> Void {
        SKStoreReviewController.requestReview()
    }
    
    @objc func clickBtn2() -> Void {
        let url = URL(string: "tel:8888888")
        UIApplication.shared.open(url!, options: [:], completionHandler: nil)
    }
    
    @objc func clickBtn3() -> Void {
        let mfm = MFMessageComposeViewController()
        mfm.recipients = ["188888888"]
        mfm.body = "今天天气怎么样?"
        present(mfm, animated: true, completion: nil)
    }
    
    func getBtn(str:String,btn:UIButton) -> UIButton {
        let btn = UIButton(frame: CGRect(x: 20, y: btn.frame.maxY + 80, width: 100, height: 40))
        btn.setTitle(str, for: .normal)
        btn.backgroundColor = UIColor.red
        return btn
    }
}
